var MobList = Array(8141000, 8140111, 8140103, 8140002, 7110301, 9500618, 9500617, 9500614);
var MobBossList = Array(7220001, 6300005, 2220000, 3220000, 9303085, 6130101, 8220007, 9600009);
var mobId;
var mob;
var modified;

function init() {
    em.setProperty("FriendlyTips", "0");
    em.setProperty("playing", "false")
}

function setup() {
    var c = em.newInstance("阿里安特竞技场");
    var d = c.setInstanceMap(980010101);
    d.respawn(false);
    c.startEventTimer(1000 * 60 * 5);
    em.setProperty("FriendlyTips", "0");
    em.setProperty("playing", "true");
    openMessageBoxInBattle(c);
    for (var b = 0; b < 15; b++) {
        mobId = MobList[Math.floor(Math.random() * MobList.length)];
        mob = em.getMonster(mobId);
        var a = c.getMapInstance(980010101);
        a.spawnMonsterOnGroundBelow(mob, new java.awt.Point(-328, -85))
    }
    return c
}

function onPlayerRegistered(b, a) {
    var c = b.getMapInstance(0);
    a.dropMessage(6, "[阿里安特竞技场] 进入到了挑战地图。");
    a.changeMap(c, c.getPortal(0));
    a.getAPI().openNpc(2101014)
}

function onTimeOut(a) {
    finish();
    a.broadcastPlayerMsg(1, "[阿里安特竞技场] 真遗憾！已超过限定挑战时间，本次挑战失败！别气馁，期待更加强大的您前来挑战~");
    a.disposeIfPlayerBelow(100, 910000000)
}

function onPlayerKilled(b, a) {}

function onPlayerRevived(b, a) {
    var c = em.getMapFactory().getMap(910000000);
    if (c != null) {
        a.changeMap(c, c.getPortal(0))
    }
    b.disposeIfPlayerBelow(100, 910000000);
    return false
}

function onMapChanged(c, b, a) {
    switch (a) {
        case 980010100:
        case 980010101:
            return
    }
    b.dropMessage(6, "[阿里安特竞技场] 已退出挑战");
    if (c.getPlayerCount() <= 0) {
        c.disposeIfPlayerBelow(100, 910000000)
    }
}

function playerExit(b, a) {
    b.disposeIfPlayerBelow(100, 910000000)
}

function onPlayerDisconnected(b, a) {
    if (b.getPlayerCount() <= 1) {
        b.disposeIfPlayerBelow(100, 910000000)
    }
    return 0
}

function onMonsterKilled(c) {
    if (player.getMap().getNumMonsters() > 0) {
        return
    }
    for (var b = 0; b < 5; b++) {
        mobId = MobList[Math.floor(Math.random() * MobList.length)];
        mob = em.getMonster(mobId);
        var a = c.getMapInstance(980010101);
        a.spawnMonsterOnGroundBelow(mob, new java.awt.Point(-328, -85))
    }
    for (var b = 0; b < 5; b++) {
        mobId = MobList[Math.floor(Math.random() * MobList.length)];
        mob = em.getMonster(mobId);
        var a = c.getMapInstance(980010101);
        a.spawnMonsterOnGroundBelow(mob, new java.awt.Point(-691, 95))
    }
    for (var b = 0; b < 5; b++) {
        mobId = MobList[Math.floor(Math.random() * MobList.length)];
        mob = em.getMonster(mobId);
        var a = c.getMapInstance(980010101);
        a.spawnMonsterOnGroundBelow(mob, new java.awt.Point(-832, 275))
    }
    mobId = MobBossList[Math.floor(Math.random() * MobList.length)];
    mob = em.getMonster(mobId);
    var a = c.getMapInstance(980010101);
    a.spawnMonsterOnGroundBelow(mob, new java.awt.Point(-311, 275))
}

function onMonsterDamaged(b, a, d, e, c) {}

function onPartyDisbanded(a) {
    a.disposeIfPlayerBelow(100, 910000000)
}

function onMapLoad(b, a) {}

function finish() {
    em.setProperty("playing", "false")
}

function openMessageBoxInBattle(b) {
    var c = b.setInstanceMap(980010101);
    if (em.getProperty("FriendlyTips") == "0") {
        c.startMapEffect("[阿里安特竞技场] 竞技场的战斗已经开始了！请赶快消灭怪物吧!", 5120026);
        for (var a = 0; a < b.getPlayerCount(); a++) {
            b.getPlayers().get(a).dropMessage(6, "[阿里安特竞技场] 竞技场的战斗已经开始了！请赶快消灭怪物吧!")
        }
        em.setProperty("FriendlyTips", "1");
        em.schedule("openMessageBoxInBattle", 1000 * 60 * 1, b)
    } else {
        if (em.getProperty("FriendlyTips") == "1") {
            c.startMapEffect("[阿里安特竞技场] 干的不错！消灭越多的怪物得到的奖励也就越丰厚！", 5120026);
            for (var a = 0; a < b.getPlayerCount(); a++) {
                b.getPlayers().get(a).dropMessage(6, "[阿里安特竞技场]  干的不错！消灭越多的怪物得到的奖励也就越丰厚！")
            }
            em.setProperty("FriendlyTips", "2");
            em.schedule("openMessageBoxInBattle", 1000 * 60 * 1, b)
        } else {
            if (em.getProperty("FriendlyTips") == "2") {
                c.startMapEffect("[阿里安特竞技场] 如果不努力一点的话。到最后可是什么奖励都没有。", 5120026);
                for (var a = 0; a < b.getPlayerCount(); a++) {
                    b.getPlayers().get(a).dropMessage(6, "[阿里安特竞技场]  如果不努力一点的话。到最后可是什么奖励都没有。")
                }
                em.setProperty("FriendlyTips", "3");
                em.schedule("openMessageBoxInBattle", 1000 * 60 * 1, b)
            } else {
                if (em.getProperty("FriendlyTips") == "3") {
                    c.startMapEffect("[阿里安特竞技场] 中途退出战役的话，就不能领取到任何的奖励。", 5120026);
                    for (var a = 0; a < b.getPlayerCount(); a++) {
                        b.getPlayers().get(a).dropMessage(6, "[阿里安特竞技场] 中途退出战役的话，就不能领取到任何的奖励。")
                    }
                    em.setProperty("FriendlyTips", "4");
                    em.schedule("openMessageBoxInBattle", 1000 * 60 * 1, b)
                } else {
                    if (em.getProperty("FriendlyTips") == "4") {
                        c.startMapEffect("[阿里安特竞技场] 还有1分钟就结束战役了，请大家抓紧时间。", 5120026);
                        for (var a = 0; a < b.getPlayerCount(); a++) {
                            b.getPlayers().get(a).dropMessage(6, "[阿里安特竞技场] 还有1分钟就结束战役了，请大家抓紧时间。")
                        }
                        em.setProperty("FriendlyTips", "5");
                        em.schedule("openMessageBoxInBattle", 1000 * 55 * 1, b)
                    } else {
                        if (em.getProperty("FriendlyTips") == "5") {
                            EndThisBattle(b)
                        }
                    }
                }
            }
        }
    }
}

function EndThisBattle(f) {
    em.setProperty("FriendlyTips", "done");
    var b = Array();
    var a = Array();
    for (var e = 0; e < f.getPlayerCount(); e++) {
        b.push(f.getPlayers().get(e).getName());
        b.push(f.getKillCount(f.getPlayers().get(e)));
        a.push(b);
        b = Array()
    }
    for (var e = 0; e < a.length; e++) {
        for (var d = 0; d < a.length; d++) {
            var c;
            if (a[e][1] > a[d][1]) {
                c = a[d];
                a[d] = a[e];
                a[e] = c
            }
        }
    }
    var g = f.setInstanceMap(980010100);
    for (var e = 0; e < f.getPlayerCount(); e++) {
        f.getPlayers().get(e).changeMap(g, g.getPortal(0));
        g.startMapEffect("[阿里安特竞技场] 现在公布结果，1分钟后自动离开此地图。", 5120026);
        f.getPlayers().get(e).dropMessage(6, "[阿里安特竞技场] 现在公布结果，1分钟后自动离开此地图。");
        f.getPlayers().get(e).getAPI().openNpc(2101017)
    }
    f.startEventTimer(1000 * 60 * 1)
};